#include "ImgUrl.h"
#include "trace_worker.h"
CImgUrl::CImgUrl(const std::string &cosUrl, const std::string &imgUrl)
:m_cosUrl(cosUrl)
,m_imgUrl(imgUrl)
{
    
}

const std::string &CImgUrl::ImgToCosUrl(std::string &cosImgUrl)
{   trace_worker();
    trace_printf("imgUrl.c_str()  %s", m_imgUrl.c_str());
    if ((m_imgUrl.find("pubinfo") != std::string::npos && m_imgUrl.find("https") != std::string::npos)
        || m_imgUrl.size() <= 0)
    {
        return m_imgUrl;
    }
 
    std::size_t startPos = m_imgUrl.size();
    std::size_t endPos = startPos;
    for (;;)
    {
        endPos = m_imgUrl.find_last_of("/", startPos);
        cosImgUrl += m_cosUrl + "pubinfo/" + m_imgUrl.substr(endPos + 1, startPos - endPos - 1);
        if (endPos == std::string::npos)
        {
            break;
        }

        startPos = m_imgUrl.find_last_of(';', endPos);
        if (startPos == std::string::npos)
        {
            break;
        }
        cosImgUrl += ";";
    }
    trace_printf("cosImgUrl.c_str()  %s", cosImgUrl.c_str());
    return cosImgUrl;
}



